package service.outils;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class ResizeImage {

	public static BufferedImage resize(BufferedImage bi, int height, int width) 
	{  
		     BufferedImage buf = new BufferedImage(width, height,  
		     bi.getType());   
		     Graphics2D g = buf.createGraphics();  
		     g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,  
		     RenderingHints.VALUE_INTERPOLATION_BILINEAR);  
		     g.drawImage(bi, 0, 0, width, height, null);  
		     g.dispose();  
		     return buf;  
    } 
	
	public static BufferedImage loadCompatibleImage(File resource)  throws IOException 
	{  
	         BufferedImage image = ImageIO.read(resource);  
	         GraphicsConfiguration configuration = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();  
	         BufferedImage compatibleImage = configuration.createCompatibleImage(  
	         image.getWidth(), image.getHeight());  
	         Graphics g = compatibleImage.getGraphics();  
	         g.drawImage(image, 0, 0, null);  
	         g.dispose();  
	         return compatibleImage;  
	     }  
} 


